Don't make description longer than allowed when truncating
authorJonas Bernoulli <jonas@bernoul.li>
Thu, 4 Aug 2022 12:05:15 +0000 (14:05 +0200)
committerJonas Bernoulli <jonas@bernoul.li>
Thu, 4 Aug 2022 12:05:15 +0000 (14:05 +0200)
Truncating the description to the allowed maximal length and then
appending an ellipsis, makes the final text longer than allowed.
The length of the ellipsis has to be taken into account.

which-key.el

index a2986269fdd5e4c850c0ec21a0659759e75afb83..2062a737abebbc4e99bfd654f77188bf77199d7f 100644 (file)
@@ -1605,8 +1605,9 @@ If KEY contains any \"special keys\" defined in
                            (if (floatp val) (truncate val) val))))))
     (if (and max (> (length desc) max))
        (let* ((last-face (get-text-property (1- (length desc)) 'face desc))
-               (dots (which-key--propertize which-key-ellipsis 'face last-face)))
-          (concat (substring desc 0 max) dots))
+               (dots (which-key--propertize which-key-ellipsis
+                                           'face last-face)))
+          (concat (substring desc 0 (- max (length dots))) dots))
       desc)))
 
 (defun which-key--highlight-face (description)